<template>
	<view>
		<home v-if="PageCur == 'home'"></home>
        <order v-if="PageCur == 'order'"></order>
        <my v-if="PageCur == 'my'"></my>
        <view class="cu-bar tabbar bg-white shadow foot">
            <view class="action" @click="NavChange" :class="PageCur=='home'?'text-orange':'text-gray'" data-cur="home">
                <view class='cuIcon-cu-image'>
                    <!--<image :src="'/static/mainMenu/home.png'"></image>-->
                    <text class=" cuIcon-home "></text>
                </view>
                <view>首页</view>
            </view>
            <view class="action" @click="NavChange" :class="PageCur=='my'?'text-orange':'text-gray'" data-cur="my">
                <view class='cuIcon-cu-image'>
                    <!--<image :src="'/static/mainMenu/my.png'"></image>-->
                    <text class=" cuIcon-my "></text>
                </view>
                <view>我的</view>
            </view>
        </view>
       <!-- <div id="logo" style="text-align: center; margin-top: 30px">
            <img id="logoImage" style="width: 60px; height: 40px;" src="/static/logo.svg"/>
            <div id="logoChar" class="logoChar">新登洛客运</div>
        </div> -->
	</view>
</template>

<script>
    import home from '../home/home'
    import order from '../order/order'
    import my from '../my/my'
    export default {
        name: 'index',
        components: {home, order, my},
        data() {
            return {
                PageCur: 'home',
				code:''
            }
        },
		onLoad(e) {
			let that = this
			let local = location.href;
			that.code = that.getParam(local,'code')
			if(that.code){
				that.wetLogin()
			}
			if(e.PageCur){
				this.PageCur = e.PageCur
			}else{
				this.PageCur ='home'
			}
		},
		onReachBottom() {
			let that = this
			if(that.PageCur=="order"){
				uni.$emit("jiazai",1)
				console.log(1111)
			}
		},
        methods: {
            NavChange: function(e) {
				uni.$off('jiazai');
                this.PageCur = e.currentTarget.dataset.cur
            },
			getParam(path, name) {
				  var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");   
				  if (reg.test(path))  
				  return unescape(RegExp.$2.replace(/\+/g, " ")); 
				  return "";    
			},
			wetLogin(){
				let that = this
				that.tui.request("api.login/wechat_in", "POST", {code: that.code}, false, false, false).then((res) => {
					if (res.code == 1) {
						uni.setStorageSync('token', res.data.info.token)
						window.location.href = 'https://reh5.wyc168.com/#/pages/index/index?PageCur=my'
					}
				}).catch((res) => {
				
				})
			},
        }
    }
</script>

<style>
	page{padding-top: 0;}
    .logoChar {
        font-size: 13px;
        -webkit-transform: scale(0.7);
    }
</style>
